//
//  PreferencesController.m
//  WSPluginSwitcher
//
//  @author	Jens Krause [www.websector.de]
//	@date		01/01/09
//  @see		http://www.websector.de/blog/
//
//  Licensed under the MIT License http://www.opensource.org/licenses/mit-license.php
//

#import "PreferencesController.h"


@implementation PreferencesController

- (id)init
{
	if (![super initWithWindowNibName:@"Preferences"]) 
		return nil;
	
	return self;
}

-(IBAction)changeFlashArchivePluginsFolder:(id)sender
{	
	
	
	// Create the File Open Panel class. 
	NSOpenPanel* oPanel = [NSOpenPanel openPanel]; 
	
	[oPanel setCanChooseDirectories:YES]; 
	[oPanel setCanChooseFiles:NO]; 
	[oPanel setCanCreateDirectories:NO]; 
	[oPanel setAllowsMultipleSelection:NO];
	[oPanel setTitle: @"Choose folder"];
	
	NSString *message = @"Select folder of your archives of Flash Plugins";
	[oPanel setMessage: message];
	
	// Display the dialog.  If the OK button was pressed,
	// process the files.
	if ( [oPanel runModalForDirectory:nil file:nil types:nil] == NSOKButton )
	{
		NSArray* files = [oPanel filenames];
		
		if ([files count] == 1) {
			
			NSString *archiveFlashPluginsFolders = [[files objectAtIndex:0] stringByStandardizingPath];
			archiveFlashPluginsFolders = [archiveFlashPluginsFolders stringByAppendingString:@"/"];
			
			// NSLog(@"pluginsFolder %@", archiveFlashPluginsFolders);	
			
			[[NSUserDefaults standardUserDefaults] setObject:archiveFlashPluginsFolders forKey: KEY_ARCHIVE_FLASH_PLUGINS_FOLDERS ];
			
			[appModel updateArchiveFlashPluginFolders];
		
		}
	}
	

}


- (void) setAppModel:(ApplicationModel *)newValue {

	appModel = newValue;
	
}

- (IBAction)checkUpdateSelectedHandler:(id)sender{	
	
	int state = [chb_checkForUpdates state];
	[[NSUserDefaults standardUserDefaults] setBool:state 
											forKey: KEY_CHECK_FOR_UPDATES];	
	
}

-(void)dealloc 
{

	[appModel release];		
	appModel = nil;
	
	[super dealloc];
	
}

@end
